package com.kunya.product.controller.portall;

import com.kunya.common.common.ServerResponse;
import com.kunya.common.util.CommonUtil;
import com.kunya.product.service.category.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zp
 * @Description: 商品分类controller
 * @date 2018/5/19 14:52
 */
@RestController
@RequestMapping("/category")
public class CategoryController {


    @Autowired
    private ICategoryService iCategoryService;


    /**
     * @author zp
     * @Description: 此接口应在cms系统中 新增分类
     * @param
     * @date 2018/5/19 14:54
     */
    @RequestMapping("/add_category")
    public ServerResponse addCategory(HttpServletRequest request, String categoryName,
                                      @RequestParam(value = "parentId", defaultValue = "0") Long parentId) {
        return iCategoryService.addCategory(categoryName, parentId, "340_");
    }

    /**
     * @author zp
     * @Description: 此接口应在cms系统中。更新分类
     * @param
     * @date 2018/5/19 14:54
     */
    @RequestMapping("/set_category_name")
    public ServerResponse setCategoryName(HttpServletRequest request, Long categoryId, String categoryName) {
        return iCategoryService.updateCategoryName(categoryId, categoryName,CommonUtil.getTablePiefix(request));
    }

    /**
     * @author zp
     * @Description: 获取子分类，不递归查询
     * @param
     * @date 2018/5/19 15:00
     */
    @RequestMapping("/get_category")
    public ServerResponse getChildrenParallelCategory(HttpServletRequest request,
                                                      @RequestParam(value = "categoryId", defaultValue = "0") Long categoryId) {
        return iCategoryService.getChildrenParallelCategory(categoryId,CommonUtil.getTablePiefix(request));

    }

    /**
     * @author zp
     * @Description: 获取子分类并递归
     * @param
     * @date 2018/5/19 15:01
     */
    @RequestMapping("get_deep_category")
    public ServerResponse getCategoryAndDeepChildrenCategory(HttpServletRequest request,
                                                             @RequestParam(value = "categoryId", defaultValue = "0") Long categoryId) {
        return iCategoryService.selectCategoryAndChildrenById(categoryId,CommonUtil.getTablePiefix(request));
    }

    /**
     * 禁用分类
     * @return
     */
    @RequestMapping("disableCategory")
    public ServerResponse disableCategory(Long categoryId,HttpServletRequest request){
        return iCategoryService.disableCategory(categoryId,CommonUtil.getTablePiefix(request));
    }
}
